/**
 * 漆水河 脚手架基础公开课
 * 2022/8/13 --- 2022/12/13
 * 有疑问可加QQ群: 809126489，后续会持续输出与大家一起成长
 */
package com.qishuihe.common.infrastructure.mq;

import com.alibaba.fastjson2.JSONObject;
import com.qishuihe.baseinterface.constant.CommonConstant;
import com.qishuihe.common.domain.log.service.LogService;
import com.qishuihe.common.domain.log.entity.LogEntity;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class ConsumerMessageListener {

       @Autowired
       private LogService logServiceImpl;

       @KafkaListener(groupId = CommonConstant.QISHUIHE_LOG_GROUP,topics = CommonConstant.QISHUIHE_LOG )
       public void  onConsumerLog(ConsumerRecord<?,?> record){
           log.info("topic:"+record.topic()+",value:"+record.value());
           LogEntity logVO = new LogEntity();
           logVO = JSONObject.parseObject(new String(record.value().toString()), LogEntity.class);
           logServiceImpl.save(logVO);
       }
}
